package com.su.kddq.controller.user;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.su.kddq.entity.user.Address;
import com.su.kddq.service.user.AddressService;
import com.su.kddq.utils.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 地址controller
 * @author sx
 */
@RestController
@RequestMapping("/hddq/express/h5/address/")
public class AddressController {

    @Autowired
    private AddressService addressService;


    /**
     * 新增地址
     * @param address
     * @return
     */
    @PostMapping("addAddress")
    public R addAddress(@RequestBody Address address) {
       boolean isAdd= addressService.addAddress(address);
       return isAdd?R.ok():R.error();
    }

    /**
     * 地址列表
     * @return
     */
    @GetMapping("addresslist")
    public R addressList() {
         List<Address> addressList= addressService.getAddressList();
         return R.ok().data("addresslist", addressList);

    }

    /**
     * 获取地址信息根据aid
     * @param id
     * @return
     */
    @GetMapping("getaddressinfo/{id}")
    public R getAddressInfo(@PathVariable Integer id) {
        Address address = addressService.getOne(new QueryWrapper<Address>().eq("id", id));
        return R.ok().data("addressInfo", address);
    }


}
